home *** CD-ROM | disk | FTP | other *** search
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Event;
- import java.awt.FileDialog;
- import java.awt.Frame;
- import java.awt.Label;
- import java.awt.LayoutManager;
- import java.awt.List;
- import java.awt.Menu;
- import java.awt.MenuBar;
- import java.awt.MenuItem;
- import java.awt.TextField;
- import java.util.Enumeration;
- import java.util.Vector;
-
- public class Frame1 extends Frame {
- Vector thingsInRoom;
- Vector thingsInSwagBag;
- FileDialog OpenFileDialog;
- List RoomList;
- List PlayerList;
- Label label1;
- Label label2;
- Label label3;
- Label label4;
- TextField textField1;
- MenuBar mainMenuBar;
- Menu menu1;
- Menu menu2;
- Menu menu3;
-
- void MoveObFromV1ToV2(Object Ob, Vector V1, Vector V2) {
- V2.addElement(Ob);
- V1.removeElement(Ob);
- }
-
- void PlayerList_DblClick(Event event) {
- Object thing = this.thingsInSwagBag.elementAt(this.PlayerList.getSelectedIndex());
- this.MoveObFromV1ToV2(thing, this.thingsInSwagBag, this.thingsInRoom);
- this.UpdateListBoxes();
- }
-
- void RoomList_DblClick(Event event) {
- Object thing = this.thingsInRoom.elementAt(this.RoomList.getSelectedIndex());
- this.MoveObFromV1ToV2(thing, this.thingsInRoom, this.thingsInSwagBag);
- this.UpdateListBoxes();
- }
-
- void UpdateListBox(List l, Vector v) {
- l.clear();
- Enumeration e = v.elements();
-
- while(e.hasMoreElements()) {
- l.addItem(((Thing)e.nextElement()).getName());
- }
-
- }
-
- void UpdateListBoxes() {
- this.UpdateListBox(this.PlayerList, this.thingsInSwagBag);
- this.UpdateListBox(this.RoomList, this.thingsInRoom);
- }
-
- void RoomList_ListSelect(Event event) {
- this.textField1.setText(((Thing)this.thingsInRoom.elementAt(this.RoomList.getSelectedIndex())).getDescription());
- }
-
- void PlayerList_ListSelect(Event event) {
- Thing t = (Thing)this.thingsInSwagBag.elementAt(this.PlayerList.getSelectedIndex());
- this.textField1.setText(t.getDescription());
- }
-
- void Open_Action(Event event) {
- this.OpenFileDialog.show();
- }
-
- void About_Action(Event event) {
- (new AboutDialog(this, "About...", false)).show();
- }
-
- void Exit_Action(Event event) {
- (new QuitDialog(this, "Quit the Application?", false)).show();
- }
-
- public Frame1() {
- ((Container)this).setLayout((LayoutManager)null);
- ((Frame)this).addNotify();
- ((Component)this).resize(((Container)this).insets().left + ((Container)this).insets().right + 457, ((Container)this).insets().top + ((Container)this).insets().bottom + 398);
- this.OpenFileDialog = new FileDialog(this, "Open", 0);
- this.RoomList = new List(0, false);
- ((Container)this).add(this.RoomList);
- this.RoomList.reshape(((Container)this).insets().left + 14, ((Container)this).insets().top + 45, 201, 225);
- this.PlayerList = new List(0, false);
- ((Container)this).add(this.PlayerList);
- this.PlayerList.reshape(((Container)this).insets().left + 238, ((Container)this).insets().top + 45, 201, 225);
- this.label1 = new Label("THINGS HERE...");
- this.label1.reshape(((Container)this).insets().left + 14, ((Container)this).insets().top + 15, 196, 15);
- ((Container)this).add(this.label1);
- this.label2 = new Label("THING YOU HAVE...");
- this.label2.reshape(((Container)this).insets().left + 238, ((Container)this).insets().top + 15, 203, 15);
- ((Container)this).add(this.label2);
- this.label3 = new Label("DOUBLE-CLICK TO TAKE");
- this.label3.reshape(((Container)this).insets().left + 14, ((Container)this).insets().top + 278, 203, 22);
- ((Container)this).add(this.label3);
- this.label4 = new Label("DOUBLE-CLICK TO DROP");
- this.label4.reshape(((Container)this).insets().left + 238, ((Container)this).insets().top + 278, 203, 24);
- ((Container)this).add(this.label4);
- this.textField1 = new TextField();
- this.textField1.reshape(((Container)this).insets().left + 14, ((Container)this).insets().top + 315, 429, 28);
- ((Container)this).add(this.textField1);
- ((Frame)this).setTitle("A Basic Application");
- this.mainMenuBar = new MenuBar();
- this.menu1 = new Menu("File");
- this.menu1.add("Open...");
- this.menu1.add("Save");
- this.menu1.add("Save As...");
- this.menu1.addSeparator();
- this.menu1.add("Exit");
- this.mainMenuBar.add(this.menu1);
- this.menu2 = new Menu("Edit");
- this.menu2.add("Cut");
- this.menu2.add("Copy");
- this.menu2.add("Paste");
- this.mainMenuBar.add(this.menu2);
- this.menu3 = new Menu("Help");
- this.menu3.add("About");
- this.mainMenuBar.add(this.menu3);
- ((Frame)this).setMenuBar(this.mainMenuBar);
- }
-
- public Frame1(String title) {
- this();
- ((Frame)this).setTitle(title);
- }
-
- public synchronized void show() {
- ((Component)this).move(50, 50);
- super.show();
- this.thingsInRoom = new Vector();
- this.thingsInSwagBag = new Vector();
- this.thingsInRoom.addElement(new Thing("Sword", "A sword encrusted with jewels"));
- this.thingsInRoom.addElement(new Thing("Troll", "An ugly, fierce-looking troll"));
- this.thingsInRoom.addElement(new Thing("Lantern", "A brass lantern"));
- this.thingsInRoom.addElement(new Thing("Pot of Noodles", "Something inedible-looking"));
- this.thingsInRoom.addElement(new Thing("Banana", "An over-ripe banana"));
- this.thingsInRoom.addElement(new Thing("Egg", "An Ostrich egg"));
- this.thingsInRoom.addElement(new Thing("Knife", "A blood-stained dagger"));
- this.thingsInSwagBag.addElement(new Thing("Coin", "A silver coin"));
- this.thingsInSwagBag.addElement(new Thing("Bubble-gum", "A pink, pre-chewed, stickly lump"));
- this.thingsInSwagBag.addElement(new Thing("Fluff", "Some pocket fluff"));
- this.UpdateListBoxes();
- }
-
- public boolean handleEvent(Event event) {
- if (event.id == 201) {
- ((Component)this).hide();
- ((Frame)this).dispose();
- System.exit(0);
- return true;
- } else {
- if (event.target == this.RoomList && event.id == 1001) {
- this.RoomList_DblClick(event);
- }
-
- if (event.target == this.PlayerList && event.id == 1001) {
- this.PlayerList_DblClick(event);
- }
-
- if (event.target == this.RoomList && event.id == 701) {
- this.RoomList_ListSelect(event);
- }
-
- if (event.target == this.PlayerList && event.id == 701) {
- this.PlayerList_ListSelect(event);
- }
-
- return super.handleEvent(event);
- }
- }
-
- public boolean action(Event event, Object arg) {
- if (event.target instanceof MenuItem) {
- String label = (String)arg;
- if (label.equalsIgnoreCase("Open...")) {
- this.Open_Action(event);
- return true;
- }
-
- if (label.equalsIgnoreCase("About")) {
- this.About_Action(event);
- return true;
- }
-
- if (label.equalsIgnoreCase("Exit")) {
- this.Exit_Action(event);
- return true;
- }
- }
-
- return super.action(event, arg);
- }
-
- public static void main(String[] args) {
- (new Frame1()).show();
- }
- }
-